<?php
declare (strict_types=1);
/**
 * @Description:
 * @Author: Chern
 * @Date: 2023/7/11
 * @Time: 11:06
 */

namespace app\model;

use think\Model;

class UserPosition extends Model
{

    protected $createTime='create_date';

    /**
     * 获取职位列表
     * @return UserPosition[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getLevelList()
    {
        return $this->order ('create_date DESC')->where (['type'=>1])->select();
    }

    /**
     * 添加职位
     * @param $data
     * @return UserPosition|Model
     */

    public function addLevel($data)
    {
        return UserPosition::create($data);
    }

    /**
     * 修改职位
     * @param $data
     * @return UserPosition
     */

    public function updateLevel($data)
    {
        return UserPosition::update($data,['id'=>$data['id']]);
    }

    /**
     * 删除职位
     * @param $id
     * @return bool
     */

    public function delLevel($id)
    {
        return UserPosition::destroy($id);
    }

    /**
     * @param $id
     * @return mixed
     */
    public  function getLevelName($id){
        return UserPosition::where(['id'=>$id])->value('level_name');
    }

    public function getRoleIds($name)
    {
        $list = $this->where('level_name','like','%'.$name.'%')->select()->toArray();
        $ids = array_column($list,'id');
        return $ids;
    }

}